import axios from 'axios';
import {config} from "../config/config";

class HTTP{
    doAjax(options){
        let type = (options.type || 'GET').toUpperCase(),
            url = config.api_base_url + options.url,
            data = options.data || null,
            success = options.success || function(){},
            error = options.error || function(){};
        if(type === 'GET'){
            axios.get(url).then(function(res){
                success(res);
            }).catch(function(err){
                error(err);
            })
        }else if(type === 'POST'){
            axios.post(url,data).then(function(res){
                success(res);
            }).catch(function(err){
                error(err);
            })
        }
    }
}

export {HTTP};
